import React, { Component } from 'react';

export default class Badge extends Component {
  state = {
    count: 2,
  };

  handleClick = () => {
    const { ghost, onChange, src } = this.props;
    const { count } = this.state;
    if (!ghost) {
      window.open(src);
    } else if (count > 8) {
      onChange();
    } else {
      this.setState((state) => ({ count: state.count + 1 }));
    }
  }

  render() {
    return (
      <a className="xixi-item" onClick={this.handleClick}>
        <img
          className="xixi-img"
          src={this.props.src}
          alt="茜茜"
        />
      </a>
    );
  }
}
